import { useModel } from "umi";
import { useReactive } from "ahooks";
import { useEffect } from "react";

const useRemoteDatabaseVersions = (versionNo) => {
    const { remoteData } = useModel("global");

    const state = useReactive({
        loading: false,
        versions: [],
    });

    const loadRemoteDatabaseVersions = async () => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-operation-center-service",
            serviceName: "/resource/referenceDatabase/person/getVersions",
            params: { versionNo },
        });
        state.versions = res || [];
        state.loading = false;
    };

    useEffect(() => {
        versionNo && loadRemoteDatabaseVersions();
    }, [versionNo]);

    return { ...state, loadRemoteDatabaseVersions };
};

export default useRemoteDatabaseVersions;
